#include <apr_uuid.h>
#include "common.h"

/** Generate a new UUID string and return it
 * \luareturn the new UUID
 */
static int lua_apr_uuid(lua_State *L) {
    apr_uuid_t uuid;
    char buffer[APR_UUID_FORMATTED_LENGTH];
    
    apr_uuid_get(&uuid);
    apr_uuid_format(buffer, &uuid);
    
    lua_pushstring(L, buffer);
    return 1;
}

static const struct luaL_reg lua_apr_uuidlib [] = {
    {"generate", lua_apr_uuid},
    {NULL, NULL}
};

int luaopen_apr_uuid(lua_State *L) {
    luaL_register(L, "apr.uuid", lua_apr_uuidlib);
    return 1;
}
